// ignore_for_file: must_be_immutable

import 'package:aitao_flutter/common_ui/circle_avatar.dart';
import 'package:aitao_flutter/common_ui/loading_view.dart';
import 'package:aitao_flutter/const/common_const.dart';
import 'package:aitao_flutter/model/personal_model.dart';
import 'package:aitao_flutter/res/r.dart';
import 'package:aitao_flutter/style/box_style.dart';
import 'package:aitao_flutter/style/color_style.dart';
import 'package:aitao_flutter/video_chat/controller/video_request_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../request/api.dart';
import '../../request/requestManager.dart';
import '../../style/edgeInsets_style.dart';
import '../../style/radius_style.dart';
import '../../style/text_style.dart';

class VideoRequestPage extends StatefulWidget {
  VideoRequestPage({super.key, required this.hangupCallBack, this.userId = 0});
  VoidCallback hangupCallBack;
  int userId;
  @override
  State<VideoRequestPage> createState() => _VideoRequestPageState();
}

class _VideoRequestPageState extends State<VideoRequestPage> {
  VideoRequestController requestController = Get.put(VideoRequestController());
  PersonalModel? model;
  @override
  void initState() {
    super.initState();
    getUserInfoData();
  }

  /// 获取用户主页信息
  void getUserInfoData() async {
    if (widget.userId == 0) return;
    var result = await RequestManager()
        .post(API.userHomeData, params: {'user_id': widget.userId});
    if (result != null && result['code'] == 0) {
      debugPrint('获取用户主页信息');
      setState(() {
        model = PersonalModel.fromJson(result['data']);
      });
      // WJLogUtils.wjLog(result);
    }
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<VideoRequestController>(builder: (controller) {
      return Scaffold(
          backgroundColor: const Color(0xFF5E5858),
          body: model == null
              ? const LoadingView()
              : CustomScrollView(
                  slivers: [
                    headerContainer(),
                    model?.label != null
                        ? gravitationContainer()
                        : SliverToBoxAdapter(
                            child: Container(
                            height: 120,
                          )),
                    bottomContainer()
                  ],
                ));
    });
  }

  Widget headerContainer() {
    return SliverToBoxAdapter(
      child: Container(
        padding: const EdgeInsets.fromLTRB(0, 40, 0, 0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            model?.intimateLevel != 0
                ? Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Image.asset(
                        ImagePath.assetsIconLevel,
                        width: 28,
                        height: 25,
                      ),
                      Box.hBox7,
                      Text(
                        'LV.${model?.intimateLevel ?? 0}${model?.intimateTitle}',
                        style: const TextStyle(
                            fontSize: 16, color: ColorStyle.whiteColor),
                      ),
                      Box.hBox15
                    ],
                  )
                : Container(),
            Box.vBox10,
            CircleAvatarWidget(
                imgHeight: 75,
                imgWidth: 75,
                url: model?.info?.avatar ?? '',
                gender: model?.info?.gender ?? 1),
            Box.vBox10,
            // const Text('默契值200',
            // style: TextStyle(fontSize: 12, color: Color(0xFFFF5D6F))),
            Text(model?.info?.nickname ?? '',
                style: const TextStyle(
                    fontSize: 16, color: ColorStyle.whiteColor)),
            Box.vBox12,
            model?.goodRate != null
                ? Row(mainAxisAlignment: MainAxisAlignment.end, children: [
                    Container(
                      alignment: Alignment.centerRight,
                      padding: EdgeInsetsStyle.edgeInsets(15, 7),
                      decoration: BoxDecoration(
                          borderRadius: RadiusStyle.setPortionRadius(
                              PortionRaduisType.raduisTopLeftAndBottomLeft, 21),
                          gradient: ColorStyle.charmValueColor),
                      child: Text(
                        '魅力值: ${model?.goodRate}',
                        style: const TextStyle(
                            fontSize: 15, color: ColorStyle.whiteColor),
                      ),
                    )
                  ])
                : Container()
          ],
        ),
      ),
    );
  }

  /// 引力标签
  Widget gravitationContainer() {
    return SliverToBoxAdapter(
      child: Container(
        padding: EdgeInsetsStyle.customMargin(18, 12, 18, 70),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text('引力标签:',
                style: TextStyle(fontSize: 16, color: ColorStyle.whiteColor)),
            Container(
              // color: ColorStyle.whiteColor,
              padding: EdgeInsetsStyle.customMargin(0, 15, 16, 0),
              child: Wrap(
                  alignment: WrapAlignment.start,
                  spacing: 23,
                  runSpacing: 15,
                  children: model!.label!.map((e) {
                    return _gravitationItemWidget('${e.label}*${e.total}');
                  }).toList()),
            )
          ],
        ),
      ),
    );
  }

  Widget _gravitationItemWidget(String title) {
    return Container(
      decoration: BoxDecoration(
          borderRadius: RadiusStyle.radiusAll(13.5),
          color: ColorStyle.themeColor),
      padding: EdgeInsetsStyle.edgeInsets(9.5, 4),
      child: Text(
        title,
        style: Styles.whiteText_13,
      ),
    );
  }

  /// 挂断
  Widget bottomContainer() {
    return SliverToBoxAdapter(
      child: Column(children: [
        const Text(
          '视频单价300贝壳/分钟',
          style: TextStyle(fontSize: 13, color: ColorStyle.whiteColor),
        ),
        Box.vBox20,
        GestureDetector(
          child: Image.asset(
            ImagePath.assetsChatHangup,
            width: 70,
            height: 70,
          ),
          onTap: () {
            widget.hangupCallBack();
          },
        ),
        Box.vBox10,
        const Text(ChatStringConst.videoCallHangup,
            style: TextStyle(fontSize: 18, color: ColorStyle.whiteColor))
      ]),
    );
  }
}
